#ifndef _WIN32_WINNT     
#define _WIN32_WINNT 0x0700
#endif
#include <windows.h>
#include <wincred.h>
#include <tchar.h>
#include <strsafe.h>

//
// Flow macros
// 

static 
void
WINAPI
_OutputDbgStr(
    __in  LPSTR szFile,
    __in  DWORD dwLine,
    __in  LPSTR szMsg,
    __in  DWORD status)
{
    CHAR rgsz [256];
    LPSTR szTag = "INFO";

    if (ERROR_SUCCESS != status)
        szTag = "ERROR";

    StringCbPrintfA(
        rgsz,
        sizeof(rgsz),
        "%s: %s - 0x%x, file %s, line %d\n",
        szTag,
        szMsg,
        status,
        szFile,
        dwLine);
    printf(rgsz);
}

#define CHECK_DWORD(_X) {                                       \
    if (ERROR_SUCCESS != (status = _X)) {                       \
        _OutputDbgStr(__FILE__, __LINE__, #_X, status);         \
        __leave;                                                \
    }                                                           \
}

//
// Main test entry point
//
int _tmain(__in int argc, __in_ecount(argc) _TCHAR* argv[])
{
    DWORD status = 0;
    ULONG ulAuthPackage = 0;
    LPVOID pvAuthBuffer = NULL;
    ULONG cbAuthBuffer = 0;
    CREDUI_INFO credUiInfo = {0};
    BOOL fSave = FALSE;

    UNREFERENCED_PARAMETER(argc);
    UNREFERENCED_PARAMETER(argv);

    __try
    {
        credUiInfo.pszCaptionText = TEXT("Bio Approval Workflow");
        credUiInfo.pszMessageText = TEXT("Please choose a credential ...");
        credUiInfo.cbSize = sizeof(credUiInfo);
        credUiInfo.hbmBanner = NULL;
        credUiInfo.hwndParent = NULL;

        CHECK_DWORD(CredUIPromptForWindowsCredentials(
            &credUiInfo,
            0,
            &ulAuthPackage,
            NULL,
            0,
            &pvAuthBuffer,
            &cbAuthBuffer,
            &fSave,
            CREDUIWIN_SECURE_PROMPT));
    }
    __finally
    {
        if (NULL != pvAuthBuffer)
            CoTaskMemFree(pvAuthBuffer);
    }

    return status;
}

